package com.appclub.kitsilano;

import java.util.Calendar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.appclub.kitsilano.activities.Activities;
import com.appclub.kitsilano.bulletin.Bulletin;
import com.appclub.kitsilano.bulletin.PDFdownloader;
import com.appclub.kitsilano.calendar.Calendar_;
import com.appclub.kitsilano.info.Info;
import com.appclub.kitsilano.other.Service_;
import com.appclub.kitsilano.settings.Settings;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
import android.content.res.Resources;

public class MainActivity extends SherlockActivity {

	private int Year;
	private int Day;
	private int D_W;
	private int D_M;
	private int Month;
	private int Jimo = 0;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
		getSupportActionBar().setBackgroundDrawable(
				getResources().getDrawable(R.drawable.tm));
		setContentView(R.layout.activity_main);

		Intent intent = new Intent(MainActivity.this, Service_.class);
		startService(intent);
		Intent i = new Intent(MainActivity.this, PDFdownloader.class);
		i.putExtra("Bulletin", 3);
		startService(i);

		Button button1 = (Button) findViewById(R.id.activities);
		button1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, Activities.class);
				startActivity(intent);
				overridePendingTransition(R.anim.right_in, R.anim.right_out);
			}
		});
		Button button2 = (Button) findViewById(R.id.bulluetin);
		button2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, Bulletin.class);
				startActivity(intent);
				overridePendingTransition(R.anim.right_in, R.anim.right_out);
			}
		});
		Button button3 = (Button) findViewById(R.id.calendar);
		button3.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, Calendar_.class);
				startActivity(intent);
				overridePendingTransition(R.anim.right_in, R.anim.right_out);
			}
		});
		Button button4 = (Button) findViewById(R.id.setting);
		button4.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, Settings.class);
				startActivity(intent);
				overridePendingTransition(R.anim.right_in, R.anim.right_out);
			}
		});
		Button button5 = (Button) findViewById(R.id.info);
		button5.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, Info.class);
				startActivity(intent);
				overridePendingTransition(R.anim.right_in, R.anim.right_out);
			}
		});

		Button jimoButton = (Button) findViewById(R.id.jimo);
		jimoButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Jimo = Jimo + 1;
				if (Jimo == 10) {
					Intent intent = new Intent(MainActivity.this, Jimo.class);
					startActivity(intent);
					overridePendingTransition(R.anim.right_in, R.anim.right_out);
				}
			}
		});
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		final Calendar c = Calendar.getInstance();
		Day = c.get(Calendar.DAY_OF_YEAR);
		D_M = c.get(Calendar.DAY_OF_MONTH);
		Year = c.get(Calendar.YEAR);
		D_W = c.get(Calendar.DAY_OF_WEEK);
		Month = c.get(Calendar.MONTH);
		Resources res = getResources();
		int[] a201304day1 = res.getIntArray(R.array.A201304Day1);
		int[] a201305day1 = res.getIntArray(R.array.A201305Day1);
		int[] a201306day1 = res.getIntArray(R.array.A201306Day1);
		int[] a201310day1 = res.getIntArray(R.array.A201310Day1);
		int[] a201304day2 = res.getIntArray(R.array.A201304Day2);
		int[] a201305day2 = res.getIntArray(R.array.A201305Day2);
		int[] a201306day2 = res.getIntArray(R.array.A201306Day2);
		int[] a201310day2 = res.getIntArray(R.array.A201310Day2);
		int[] a201304day1A = res.getIntArray(R.array.A201304Day1A);
		int[] a201305day1A = res.getIntArray(R.array.A201305Day1A);
		int[] a201306day1A = res.getIntArray(R.array.A201306Day1A);
		int[] a201310day1A = res.getIntArray(R.array.A201310Day1A);
		int[] a201304day2A = res.getIntArray(R.array.A201304Day2A);
		int[] a201305day2A = res.getIntArray(R.array.A201305Day2A);
		int[] a201306day2A = res.getIntArray(R.array.A201306Day2A);
		int[] a201310day2A = res.getIntArray(R.array.A201310Day2A);
		int[] IPP = res.getIntArray(R.array.IPP);
		int[] Pro_D = res.getIntArray(R.array.Pro_D);
		int[] others = res.getIntArray(R.array.others);
		String[] others_name = res.getStringArray(R.array.others_name);
		final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
		inflater.inflate(R.menu.day, menu);
		if (Year == 2013) {
			if (D_W == Calendar.SATURDAY) {
				menu.getItem(0).setTitle("No School");
			}
			if (D_W == Calendar.SUNDAY) {
				menu.getItem(0).setTitle("No School");
			}
			if (Month == Calendar.APRIL) {
				for (int i = 0; i < a201304day1.length; i++) {
					if (D_M == a201304day1[i]) {
						menu.getItem(0).setTitle("Day1");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day1 IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201304day2.length; i++) {
					if (D_M == a201304day2[i]) {
						menu.getItem(0).setTitle("Day2");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day2 IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201304day1A.length; i++) {
					if (D_M == a201304day1A[i]) {
						menu.getItem(0).setTitle("Day1A");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day1A IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201304day2A.length; i++) {
					if (D_M == a201304day2A[i]) {
						menu.getItem(0).setTitle("Day2A");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day2A IPP");
							}
						}
					}
				}
			}
			if (Month == Calendar.MAY) {
				for (int i = 0; i < a201305day1.length; i++) {
					if (D_M == a201305day1[i]) {
						menu.getItem(0).setTitle("Day1");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day1 IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201305day2.length; i++) {
					if (D_M == a201305day2[i]) {
						menu.getItem(0).setTitle("Day2");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day2 IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201305day2A.length; i++) {
					if (D_M == a201305day2A[i]) {
						menu.getItem(0).setTitle("Day2A");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day2A IPP");
							}
						}

					}
				}
				for (int i = 0; i < a201305day1A.length; i++) {
					if (D_M == a201305day1A[i]) {
						menu.getItem(0).setTitle("Day1A");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day1A IPP");
							}
						}
					}
				}
			}
			if (Month == Calendar.JUNE) {
				for (int i = 0; i < a201306day1.length; i++) {
					if (D_M == a201306day1[i]) {
						menu.getItem(0).setTitle("Day1");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day1 IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201306day2.length; i++) {
					if (D_M == a201306day2[i]) {
						menu.getItem(0).setTitle("Day2");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day2 IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201306day1A.length; i++) {
					if (D_M == a201306day1A[i]) {
						menu.getItem(0).setTitle("Day1A");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day1A IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201306day2A.length; i++) {
					if (D_M == a201306day2A[i]) {
						menu.getItem(0).setTitle("Day2A");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day2A IPP");
							}
						}
					}
				}
			}
			if (Month == Calendar.OCTOBER) {
				for (int i = 0; i < a201310day1.length; i++) {
					if (D_M == a201310day1[i]) {
						menu.getItem(0).setTitle("Day1");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day1 IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201310day2.length; i++) {
					if (D_M == a201310day2[i]) {
						menu.getItem(0).setTitle("Day2");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day2 IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201310day1A.length; i++) {
					if (D_M == a201310day1A[i]) {
						menu.getItem(0).setTitle("Day1A");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day1A IPP");
							}
						}
					}
				}
				for (int i = 0; i < a201310day2A.length; i++) {
					if (D_M == a201310day2A[i]) {
						menu.getItem(0).setTitle("Day2A");
						for (int ii = 0; ii < IPP.length; ii++) {
							if (Day == IPP[ii]) {
								menu.getItem(0).setTitle("Day2A IPP");
							}
						}
					}
				}
			}
			for (int i = 0; i < Pro_D.length; i++) {
				if (Day == Pro_D[i]) {
					menu.getItem(0).setTitle("Pro-D");
				}
			}
			for (int i = 0; i < others.length; i++) {
				if (Day == others[i]) {
					menu.getItem(0).setTitle(others_name[i]);
				}
			}
		} else {
			menu.getItem(0).setTitle("Please Update this APP");
		}
		return super.onCreateOptionsMenu(menu);
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		int item_id = item.getItemId();
		if (item_id == R.id.day) {
			Intent intent = new Intent(MainActivity.this, Calendar_.class);
			startActivity(intent);
			overridePendingTransition(R.anim.right_in, R.anim.right_out);
		}
		return false;
	}
}